package com.lishao.soccer.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.lishao.soccer.bean.entity.TmMember;
import com.lishao.soccer.bean.entity.TmScoreList;
import com.lishao.soccer.bean.form.TmScoreListForm;
import com.lishao.soccer.service.TmScoreListService;
import com.lishao.system.security.providers.SecurityUser;
import com.lishao.system.utils.ActionUtil;
import com.opensymphony.xwork2.ActionSupport;

import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;

public class TmScoreListAction extends ActionSupport {
	TmScoreListService tmScoreListService;
	Long teamId;
	Long tmScoreListId;
	String jsonStr;
	
	public String selectByTeam() throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		List<TmScoreList> tmScoreList = tmScoreListService.selectByTeam(teamId);
		
		Map resMap = new HashMap();
		resMap.put("tmScoreList", tmScoreList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String selectById()throws Exception{
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpServletResponse response = ServletActionContext.getResponse();

		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		
		TmScoreList tmScoreList=tmScoreListService.selectByPrimaryKey(tmScoreListId);
		
		Map resMap = new HashMap();
		resMap.put("tmScoreList", tmScoreList);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	public String saveTmScoreList() throws Exception{
		String strMessage = "";
		HttpServletRequest request = ServletActionContext.getRequest();
		HttpSession session = request.getSession();
		SecurityUser secUser = (SecurityUser)session.getAttribute("LOGIN_KEY");
		TmScoreListForm tmScoreListForm = (TmScoreListForm)JSONObject.toBean(JSONObject.fromObject(jsonStr, new JsonConfig()), TmScoreListForm.class);
		boolean bResult = tmScoreListService.saveScoreList(tmScoreListForm, secUser.getSmUser());
		Map resMap = new HashMap();
		resMap.put("bResult", bResult);
		new ActionUtil().writeMap(resMap);
		
		return null;
	}
	
	//get set
	public TmScoreListService getTmScoreListService() {
		return tmScoreListService;
	}

	public void setTmScoreListService(TmScoreListService tmScoreListService) {
		this.tmScoreListService = tmScoreListService;
	}

	public Long getTeamId() {
		return teamId;
	}

	public void setTeamId(Long teamId) {
		this.teamId = teamId;
	}

	public Long getTmScoreListId() {
		return tmScoreListId;
	}

	public void setTmScoreListId(Long tmScoreListId) {
		this.tmScoreListId = tmScoreListId;
	}

	public String getJsonStr() {
		return jsonStr;
	}

	public void setJsonStr(String jsonStr) {
		this.jsonStr = jsonStr;
	}
	
}
